﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.IO;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;

namespace EventLogReaderService
{
    public partial class EventLogReaderService : ServiceBase
    {
        public EventLogReaderService()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            backgroundWorker1.RunWorkerAsync();
        }

        protected override void OnStop()
        {
            EventLogReader.Stop();
        }

        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                EventLogReader.Start();
            }
            catch (Exception ex)
            {
                StreamWriter ew = new StreamWriter(ConfigurationManager.AppSettings["ErrorLogPath"].ToString(), true, Encoding.UTF8);
                ew.WriteLine(ex.Message + "\n\r" + ex.StackTrace);
            }
            finally
            {

            }
        }
    }
}
